package com.carol.lmsbe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.carol.lmsbe.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户Mapper接口
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    
    /**
     * 根据用户名查找用户（包含实验室信息）
     */
    @Select("SELECT u.*, l.name as laboratory_name " +
            "FROM user u " +
            "LEFT JOIN laboratory l ON u.laboratory_id = l.id " +
            "WHERE u.username = #{username}")
    User selectByUsernameWithLaboratory(@Param("username") String username);
    
    /**
     * 根据角色查询用户列表
     */
    @Select("SELECT * FROM user WHERE role = #{role}")
    List<User> selectByRole(@Param("role") String role);
}
